﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using SFA;
using System.Configuration;

public partial class Common_CandidatDetailsUC : System.Web.UI.UserControl
{

    public string DocumentPath = ConfigurationSettings.AppSettings["ProfilePic"];
    public string ConfigReqPayString = ConfigurationSettings.AppSettings["ReqPayString"];
    public string ConfigPaymentpath = ConfigurationSettings.AppSettings["Paymentpath"];
    public string CVPath = ConfigurationSettings.AppSettings["CvPath"];
    int cid = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        Guid UserId = new Guid(Convert.ToString(Session["UserID"]));
        if(Session["CandidateID"]==null)
        {
            
        }
        else
        {
            cid = Convert.ToInt32(Session["CandidateID"]);

        }
        GetCandidateDetailsDataSet(UserId, cid);
        Session["CandidateID"] = cid;
          
            
    }

    public void GetCandidateData(DataTable DtCandidateData)
    {

        tdAccreditationType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["AccrediationType"]);
        string strCandidateType = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        tdCandidateType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        if (strCandidateType == "Independent")
        {
            trMarketReserachCompany.Visible = false;
        }
        else
        {
            trMarketReserachCompany.Visible = true;
            tdMarketReserachCompany.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CompanyName"]);
        }


        tdEmail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Email"]);
        tdFirstName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["FirstName"]);
        // tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);

        string middlename = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);
        if (middlename == "")
        {
            tdMiddleName.InnerHtml = "&nbsp;&nbsp;-";

        }
        else
        {
            tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);

        }

        tdLastName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LastName"]);
        tdDOB.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["conDOB"]);
        string strGender = Convert.ToString(DtCandidateData.Rows[0]["Gender"]);

        tdNationality.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["NationalityName"]);
        tdContectAddress.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ContactAddress"]);
        tdCountry.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CountryName"]);
        tdState.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["StateName"]);
        tdZipCode.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ZipCode"]);

        string otherphoneno = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        string[] otherphonenoparts = otherphoneno.Split('-');
        if (otherphonenoparts[0] == "" || otherphonenoparts[1] == "" || otherphonenoparts[2] == "")
        { tdHomePhoneNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdHomePhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);

        }


        string phoneno = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);
        string[] phonenoparts = phoneno.Split('-');
        if (phonenoparts[0] == "" || phonenoparts[1] == "" || phonenoparts[2] == "")
        { tdWorkPhoneNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        }


        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string mobileno = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string[] mobparts = mobileno.Split('-');
        if (mobparts[1] == "")
        { tdMobileNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);

        }



        //tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);

        //tdGraduationID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationID"]);
        tdGraduation.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationType"]);
        //tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdUniversity.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["University"]);
        //tdQualificationStatusID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatusID"]);
        tdStatus.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatus"]);
        txtStatusID.Text = Convert.ToString(DtCandidateData.Rows[0]["StatusID"]);

        string strProfilePath = Convert.ToString(DtCandidateData.Rows[0]["ProfilePicturePath"]);
        if (strProfilePath == "")
        {
            Image1.ImageUrl = "~/Images/Unknown2.jpg";

        }
        else
        {
            Image1.ImageUrl = DocumentPath + '/' + strProfilePath;
        }

        tdCandidateLanguageDetail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LanguageList"]);
        string strPath = string.Empty;
        string strCvTitle = Convert.ToString(DtCandidateData.Rows[0]["CVPath"]);
        string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;
        string strUCvpath = CVPath.Remove(0, 1);

        strPath = strAuthority + strUCvpath + strCvTitle;

        tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Click Here</b>" + "</a>";



    }

    private DataSet GetCandidateDetailsDataSet(Guid Id, int cid)
    {
        DataSet objDs=null;
        try
        {
            objDs = new UserMasterBAL().GetCandidateDetails(Id, cid);

            GetCandidateData(objDs.Tables[0]);
            GetUsersCompany(objDs.Tables[1]);


            string strStatuaID = txtStatusID.Text.Trim();
            int intStatusID = Convert.ToInt32(strStatuaID);
            
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }

    private void GetUsersCompany(DataTable DtUsersCompanyData)
    {
        gvUser.DataSource = (DtUsersCompanyData);
        gvUser.DataBind();
    }

    public string getRemoteAddr()
    {
        string UserIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (UserIPAddress == null)
        {
            UserIPAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        return UserIPAddress;
    }
    public string getSecureCookie(HttpRequest Request)
    {

        HttpCookie secureCookie = Request.Cookies["vsc"];
        if (secureCookie != null)
        {
            return secureCookie.ToString();
        }
        else
        {
            return "";
        }


    }






}